package cn.com.spic.demo.impl;

import cn.com.spic.demo.api.OrganizationService;
import cn.com.spic.demo.dao.OrganizationDAO;
import cn.com.spic.demo.dto.EchartDTO;
import cn.com.spic.demo.dto.OrgaizationDTO;
import cn.com.spic.demo.dto.SecGroupMessageDTO;
import cn.com.spic.demo.po.OrganizationPO;
import cn.com.spic.demo.po.SecGroupMessagePO;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
@RequiredArgsConstructor
public class OrganizationServiceImpl implements OrganizationService {
    @Autowired
    private OrganizationDAO organizationDAO;

    public List<OrgaizationDTO> getOrgaizations(String[] orgCodes) {
        List<OrganizationPO> organizationPOS = organizationDAO.getOrganizations(orgCodes);
        List<OrgaizationDTO> orgaizationDTOS = new ArrayList<>();
        for (OrganizationPO po : organizationPOS) {
            OrgaizationDTO dto = new OrgaizationDTO();
            BeanUtils.copyProperties(po, dto);
            orgaizationDTOS.add(dto);
        }

        return orgaizationDTOS;
    }

    @Override
    public List<OrgaizationDTO> getAllOrg() {
        List<OrganizationPO> pos = organizationDAO.getAllOrg();
        List<OrgaizationDTO> dtos = new ArrayList<>();
        for (OrganizationPO org : pos) {
            OrgaizationDTO dto = new OrgaizationDTO();
            BeanUtils.copyProperties(org, dto);
            dtos.add(dto);
        }
        return dtos;
    }

    @Override
    public List<OrgaizationDTO> getAllOrgs(Map<String, Integer> map) {
        List<OrganizationPO> pos = organizationDAO.getAllOrgs(map);
        List<OrgaizationDTO> dtos = new ArrayList<>();
        for (OrganizationPO org : pos) {
            OrgaizationDTO dto = new OrgaizationDTO();
            BeanUtils.copyProperties(org, dto);
            dtos.add(dto);
        }
        return dtos;
    }

    @Override
    public List<String> getOrgByLike(String askWay) {
        return organizationDAO.getOrgByLike(askWay);
    }

    @Override
    public List<SecGroupMessageDTO> getSecGroupInFourAction() {
        List<SecGroupMessageDTO> orgaizationDTO = new ArrayList<>();
        List<SecGroupMessagePO> organizationPOS = organizationDAO.getSecGroupInFourAction();
        if (organizationPOS != null && organizationPOS.size() > 0) {
            for (SecGroupMessagePO po : organizationPOS) {
                SecGroupMessageDTO dto = new SecGroupMessageDTO();
                BeanUtils.copyProperties(po, dto);
                orgaizationDTO.add(dto);
            }
        }
        return orgaizationDTO;
    }

    @Override
    public List<SecGroupMessageDTO> getSecGroupInThreeAction() {
        List<SecGroupMessageDTO> orgaizationDTO = new ArrayList<>();
        List<SecGroupMessagePO> organizationPOS = organizationDAO.getSecGroupInThreeAction();
        if (organizationPOS != null && organizationPOS.size() > 0) {
            for (SecGroupMessagePO po : organizationPOS) {
                SecGroupMessageDTO dto = new SecGroupMessageDTO();
                BeanUtils.copyProperties(po, dto);
                orgaizationDTO.add(dto);
            }
        }
        return orgaizationDTO;
    }

    @Override
    public List<EchartDTO> GetJDXPo() {
        return organizationDAO.GetJDXPo();
    }

    @Override
    public String getOrgNameByCode(String code) {
        return organizationDAO.getOrgNameByCode(code);
    }

//    public List<OrgaizationDTO> getAllOrganizations() {
//        List<OrgaizationDTO> orgaizationDTO = new ArrayList<>();
//        List<OrganizationPO> organizationPOS = OrgService.findAll();
//        if(organizationPOS!=null && organizationPOS.size()>0){
//            for (OrganizationPO po:organizationPOS){
//                OrgaizationDTO dto = new OrgaizationDTO();
//                BeanUtils.copyProperties(po,dto);
//                orgaizationDTO.add(dto);
//            }
//        }
//        return orgaizationDTO;
//    }
}
